
/**
* from表单初始化
*/
function formTagInit(obj){
	//初始化
	 $(obj).removeClass("ipt-txt-error");
	  var _tips = $(obj).siblings("span").last();
	 _tips.removeClass().addClass("form-tips");
	 _tips.html($(obj).attr("tips"));
}


/**
* 表单验证
*/
function checkFormTag(obj,permitedNull){
	var checkObj = $(obj);
	var name = trim(checkObj.val());
	var _tips = checkObj.siblings("span").last();
	if(name.length<1){
		if(permitedNull == undefined || permitedNull==0){
			checkObj.addClass("ipt-txt-error");
	  		 _tips.html(checkObj.attr("tips"));
			 _tips.removeClass().addClass("form-tips form-tips-error");
			return false;
		}
		return true;
	}else if(typeof(checkObj.attr("maxlength"))!=undefined&&strLength(name)>checkObj.attr("maxLength")){
		checkObj.addClass("ipt-txt-error");
	  	_tips.html("请控制在"+checkObj.attr("maxlength")+"个字符以内（"+checkObj.attr("maxlength")/2+"个汉字）");
		 _tips.removeClass().addClass("form-tips form-tips-error");
		return false;
	}else{
		 _tips.html("");
		 checkObj.removeClass("ipt-txt-error");
		 _tips.removeClass().addClass("form-tips form-tips-ok");
		 return true;
	}
}

/**
 * 邮箱验证
 * @return
 */
function checkFormEmail(obj){
	var checkObj = $(obj);
	var name = trim(checkObj.val());
	var _tips = checkObj.siblings("span").last();
	if(name.length<1){
		checkObj.addClass("ipt-txt-error");
  		 _tips.html(checkObj.attr("tips"));
		 _tips.removeClass().addClass("form-tips form-tips-error");
		return false;
	}else if(typeof(checkObj.attr("maxlength"))!=undefined&&strLength(name)>checkObj.attr("maxLength")){
		checkObj.addClass("ipt-txt-error");
	  	_tips.html("可输入最大字符数"+name.length);
		 _tips.removeClass().addClass("form-tips form-tips-error");
		return false;
	}else if(!isEmail(name)){
		checkObj.addClass("ipt-txt-error");
	  	_tips.html("邮箱格式不正确");
		 _tips.removeClass().addClass("form-tips form-tips-error");
		return false;
	}else{
		 _tips.html("");
		 checkObj.removeClass("ipt-txt-error");
		 _tips.removeClass().addClass("form-tips form-tips-ok");
		 return true;
	}
}

/**
 * 邮箱验证
 * @return
 */
function checkURL(obj,permitedNull){
	var checkObj = $(obj);
	var name = trim(checkObj.val());
	var _tips = checkObj.siblings("span").last();
	if(name.length<1){
		if(permitedNull == undefined || permitedNull==0){
			checkObj.addClass("ipt-txt-error");
	  		 _tips.html(checkObj.attr("tips"));
			 _tips.removeClass().addClass("form-tips form-tips-error");
			return false;
		}
		return true;
	}else if(typeof(checkObj.attr("maxlength"))!=undefined&&strLength(name)>checkObj.attr("maxLength")){
		checkObj.addClass("ipt-txt-error");
	  	_tips.html("可输入最大字符数"+name.length);
		 _tips.removeClass().addClass("form-tips form-tips-error");
		return false;
	}else if(!isURL(name)){
		checkObj.addClass("ipt-txt-error");
	  	_tips.html("URL格式不正确");
		 _tips.removeClass().addClass("form-tips form-tips-error");
		return false;
	}else{
		 _tips.html("");
		 checkObj.removeClass("ipt-txt-error");
		 _tips.removeClass().addClass("form-tips form-tips-ok");
		 return true;
	}
}

/**
 * 手机验证
 * @return
 */
function checkFormPhone(obj){
	var checkObj = $(obj);
	var name = trim(checkObj.val());
	var _tips = checkObj.siblings("span").last();
	if(name.length<1){
		checkObj.addClass("ipt-txt-error");
  		 _tips.html(checkObj.attr("tips"));
		 _tips.removeClass().addClass("form-tips form-tips-error");
		return false;
	}else if(!isMobile(name)){
		checkObj.addClass("ipt-txt-error");
	  	_tips.html("手机格式不正确");
		 _tips.removeClass().addClass("form-tips form-tips-error");
		return false;
	}else{
		 _tips.html("");
		 checkObj.removeClass("ipt-txt-error");
		 _tips.removeClass().addClass("form-tips form-tips-ok");
		 return true;
	}
}

/**
 * 数字验证
 * @return
 */
function checkFormNumber(obj){
	var checkObj = $(obj);
	var name = trim(checkObj.val());
	var _tips = checkObj.siblings("span").last();
	if(name.length<1){
		checkObj.addClass("ipt-txt-error");
  		 _tips.html(checkObj.attr("tips"));
		 _tips.removeClass().addClass("form-tips form-tips-error");
		return false;
	}else if(typeof(checkObj.attr("maxlength"))!=undefined&&strLength(name)>checkObj.attr("maxLength")||!isInt(name)){
		checkObj.addClass("ipt-txt-error");
	  	_tips.html("输入无效");
		 _tips.removeClass().addClass("form-tips form-tips-error");
		return false;
	}else{
		 _tips.html("");
		 checkObj.removeClass("ipt-txt-error");
		 _tips.removeClass().addClass("form-tips form-tips-ok");
		 return true;
	}
}

/**
 * 跳转到错误的锚点
 * @param tagId
 * @return
 */
function goToPosition(tagId){
	location.href = "#"+tagId;
	$("#"+tagId).blur();
}
